﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameLibrary.Settlement
{
    using Interfaces;
    [Serializable]
    public class SettlementInfo: 
        IInfo,
        IMapObject
    {
        #region variables

        public SettlementFlags Type { get; private set; }
        public uint SuboridinateTo { get; private set; }
        public Buildings Buildings { get; private set; }
        public Dictionary<uint, SettlementInfo> villages { get; private set; }
        public uint BaseProduction { get; private set; }
        public uint Income { get; private set; }
        public uint Production { get; private set; }
        public uint TimeStamp { get; private set; }

        #endregion

        #region constructor
        public SettlementInfo():base(0,Position.Zero,0)
        {
            this.Type = SettlementFlags.Village;
        }
        public SettlementInfo(Settlement settlement)
            : base(settlement.ID, settlement.Location, settlement.OwnerID)
        {
            Type = settlement.Type;
            SuboridinateTo = settlement.SubordinateOf;
            Buildings = new Buildings();
            foreach (var b in settlement.GetCurrentBuildings())
                this.Buildings.SetLevel(b, settlement.GetBuildingLevel(b));
            if (settlement.Type == SettlementFlags.City)
            {
                villages = new Dictionary<uint, SettlementInfo>();
                foreach (var a in settlement.GetVillages())
                    villages.Add(a.ID, a.Info);
            }
            else
                villages = new Dictionary<uint,SettlementInfo>();
            Income = settlement.Income;
            Production = settlement.Production;
            BaseProduction = settlement.BaseProduction;
            TimeStamp = GameManager.TurnNumber;
        }

        public SettlementInfo(SettlementInfo info) : base(info)
        {
            this.Type = info.Type;
            this.SuboridinateTo = info.SuboridinateTo;
            this.Buildings = new Buildings(info.Buildings);            
            this.villages = new Dictionary<uint, SettlementInfo>(info.villages);
            this.Income = info.Income;
            this.Production = info.Production;
            this.BaseProduction = info.BaseProduction;
            this.TimeStamp = info.TimeStamp;
        }

        #endregion
    }
}
